﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

namespace SpectrEngine.Framework
{
    public class GameNode
        : IGameNode, IUpdateableItem
    {
        public GameNode(Game game)
        {
            this.game = game;
            disposing = false;
            updateOrder = 0;
            enabled = true;
        }

        private Game game;
        public Game Game
        {
            get { return game; }
        }

        private GameNode parent;
        public GameNode Parent
        {
            get { return parent; }
            set { parent = value; }
        }


        private bool disposing;
        public bool Disposing
        {
            get { return disposing; }
        }

        public event EventHandler Disposed;

        protected internal virtual void onDispose()
        {
            if (Disposed != null)
            {
                Disposed(this, EventArgs.Empty);
            }
        }

        public virtual void Dispose()
        {
            if (!disposing)
            {
                onDispose();
            }

            disposing = true;
        }

        private int updateOrder;
        public int UpdateOrder
        {
            get { return updateOrder; }
            set
            {
                if (updateOrder != value)
                {
                    updateOrder = value;
                    onUpdateOrderChanged();
                }
            }
        }

        protected internal virtual void onUpdateOrderChanged()
        {
            if (UpdateOrderChanged != null)
            {
                UpdateOrderChanged(this, EventArgs.Empty);
            }
        }

        private bool enabled;
        public bool Enabled
        {
            get { return enabled; }
            set
            {
                if (enabled != value)
                {
                    enabled = value;
                    onEnabledChanged();
                }
            }
        }

        protected internal virtual void onEnabledChanged()
        {
            if (EnabledChanged != null)
            {
                EnabledChanged(this, EventArgs.Empty);
            }
        }

        public event EventHandler UpdateOrderChanged;

        public event EventHandler EnabledChanged;

        public virtual void Update(GameTime gameTime)
        {
        }

    }
}
